package compare;

public class Person implements Comparable<Person> {
    private final int height;
    private final int weight;
    private final int score;
    private final int level;
    //只比较level
//    @Override
//    public int compareTo(Person o){
//        if(this.level > o.level){
//            return 1;
//        }else if(this.level < o.level){
//            return -1;
//        }else{
//            return 0;
//        }
//    }

    //当 level 相等时，进行下一个的比较,按照优先级 level > score > height > weight 进行比较
    @Override
    public int compareTo(Person o){
        int r = this.level - o.level;
        if(r != 0){
            return r;
        }
        r = this.score - o.score;
        if(r != 0){
            return r;
        }
        r = this.height - o.height;
        if(r != 0){
            return r;
        }
        return this.weight - o.weight;
    }

    public Person(int height,int weight,int score,int level){
        this.height = height;
        this.weight = weight;
        this.score = score;
        this.level = level;
    }
    @Override
    public String toString(){
        return "Person{" + " height=" + height + " weight=" + weight + " score=" + score + " level" + level +"}";
    }
}
